<template>
	<el-dialog v-model="dialogFormVisible" title='再次申请出库' width="30%" center>
		<span >请确认，此操作将再次申请产品出库</span>
		<template #footer>
			<span class="dialog-footer">
				<el-button type="primary" @click="applyProduct">
					确定
				</el-button>
			</span>
		</template>
	</el-dialog>
</template>

<script lang="ts" setup>
	import { ElMessage } from 'element-plus'
	import {getUserInfor,editAdmin,changeIdentityToUser,deleteUser} from '@/api/userinfor.js'
	import { bus } from "@/utils/mitt.js"
	import { reactive, ref,onBeforeUnmount } from 'vue'
	import {applyOutProduct} from '@/api/product.js'
	bus.on('againId', (row : any) => {
			formData.id = row.id
			formData.product_inwarehouse_number = row.product_inwarehouse_number
			formData.product_name = row.product_name
			formData.product_single_price = row.product_single_price
			formData.product_out_apply_person = row.product_out_apply_person
			formData.product_out_number = row.product_out_number
	})
		
		interface formData {
			id : number,
			product_name: string,
			product_out_id : number,
			product_inwarehouse_number : number,
			product_single_price:number,
			product_out_number : number,
			product_out_apply_person : string,
			apply_memo : string,
		}
		
		const formData : formData = reactive({
			id: null,
			product_name:null,
			product_out_id: null,
	        product_inwarehouse_number:null,
			product_single_price:null,
			product_out_number: null,
			product_out_apply_person: '',
			apply_memo: ''
		})
	const emit=defineEmits(['success'])
	const applyProduct=async()=>{
			const res=await applyOutProduct(formData)
			if(res.status===0){
				ElMessage({
				    message: '产品申请出库成功',
				    type: 'success',
				  })
				  emit('success')
				  dialogFormVisible.value=false
			}else{
				ElMessage.error('产品申请出库失败')
			}
	}
	
	
	// 弹窗开关  编辑管理员
    const dialogFormVisible = ref(false)
	const open=()=>{
		dialogFormVisible.value=true
	}
	defineExpose({
		open
	})
	
	onBeforeUnmount(()=>{
		bus.all.clear()
	})
</script>

<style lang="scss" scoped>
	
</style>